// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: qiulin_JXGM ql1746365080@gmail.com
 * @Date: 2024-11-07 16:32:26
 * @LastEditors: qiulin 1746365080@qq.com
 * @LastEditTime: 2024-12-08 00:27:34
 * @FilePath: \SGFEM\Import\BDFImport\test\Element\CWELDParserTest.cpp
 */

#include "Import/BDFImport/BulkData/Element/CWELDParser.h"

#include "gtest/gtest.h"

#include "DataStructure/Common/Constant.h"
#include "DataStructure/Input/Element/CWELDData.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;

using SG::DataStructure::Common::TOLERANCE;
using namespace SG::DataStructure;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;
class CWELDParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (CWELDParserTest, ParseEntry1)
{
    std::vector<std::string> Entry = { "CWELD          1       2      81GRIDID                  QQ              +00000A6",
                                       "+00000A6      44      51      56      54                                +00000A7",
                                       "+00000A7      35      36      33      31" };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCWELD (DB_SERVICEFACTORY, dividedEntryInfo);
    SG::DataStructure::FEM::CWELDData data;
    DB_SERVICEFACTORY->get<IElementService> ()->FindByIndex (0, data);
    ASSERT_TRUE (data.m_id == 1);
}

TEST_F (CWELDParserTest, ParseEntry2)
{
    std::vector<std::string> Entry1 = { "CWELD    110     10      143     ELEMID", "         6       78" };
    BDF::divideBulkEntry (Entry1, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCWELD (DB_SERVICEFACTORY, dividedEntryInfo);
    SG::DataStructure::FEM::CWELDData data;
    DB_SERVICEFACTORY->get<IElementService> ()->FindByIndex (1, data);
    ASSERT_TRUE (data.m_id == 110);
}

TEST_F (CWELDParserTest, ParseEntry3)
{
    std::vector<std::string> Entry2 = { "CWELD          2       2     127PARTPAT                                 +00000FD",
                                        "+00000FD       1       3" };
    BDF::divideBulkEntry (Entry2, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCWELD (DB_SERVICEFACTORY, dividedEntryInfo);
    SG::DataStructure::FEM::CWELDData data;
    DB_SERVICEFACTORY->get<IElementService> ()->FindById (2, data);
    ASSERT_TRUE (data.m_id == 2);
}

TEST_F (CWELDParserTest, ParseEntry4)
{
    std::vector<std::string> Entry3 = { "CWELD          3       2      41ELEMID                                  +00000FC",
                                        "+00000FC      64" };
    BDF::divideBulkEntry (Entry3, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCWELD (DB_SERVICEFACTORY, dividedEntryInfo);
    SG::DataStructure::FEM::CWELDData data;
    DB_SERVICEFACTORY->get<IElementService> ()->FindById (3, data);
    ASSERT_TRUE (data.m_id == 3);
    ASSERT_TRUE (data.GetFormat () == SG::DataStructure::FEM::CWELDFormats::FORMAT_ElemID);
}

TEST_F (CWELDParserTest, ParseEntry5)
{
    std::vector<std::string> Entry4 = { "CWELD          4       4      37GRIDID                  QT              +00000FF",
                                        "+00000FF      77      85      90      81                                +0000100",
                                        "" };
    BDF::divideBulkEntry (Entry4, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCWELD (DB_SERVICEFACTORY, dividedEntryInfo);
    SG::DataStructure::FEM::CWELDData data;
    DB_SERVICEFACTORY->get<IElementService> ()->FindById (4, data);
    ASSERT_TRUE (data.m_id == 4);
    ASSERT_TRUE (data.GetSPType (true) == SG::DataStructure::FEM::SurfaceType::Type_Quad);
    ASSERT_TRUE (data.GetSPType (false) == SG::DataStructure::FEM::SurfaceType::Type_Tri);
}
